Clarify usage of IUnionMembers interface - #55183
Conversation
clarify Union member providers
BillWagner
left a comment
There was a problem hiding this comment.
Hi @BarionLP
This is a good start. I'd like to see the example updated to include the additional members. So, instead of:
[System.Runtime.CompilerServices.Union]
public record class Outcome<T> : Outcome<T>.IUnionMembers
{
private readonly object? _value;
private Outcome(object? value) => _value = value;
public interface IUnionMembers
{
static Outcome<T> Create(T? value) => new(value);
static Outcome<T> Create(Exception? value) => new(value);
object? Value { get; }
}
object? IUnionMembers.Value => _value;
}The sample should include:
[System.Runtime.CompilerServices.Union]
public record class Outcome<T> : Outcome<T>.IUnionMembers
{
private readonly object? _value;
private Outcome(object? value) => _value = value;
public interface IUnionMembers
{
static Outcome<T> Create(T? value) => new(value);
static Outcome<T> Create(Exception? value) => new(value);
object? Value { get; }
bool TryGetValue(out T value);
bool TryGetValue(out Exception value);
}
object? IUnionMembers.Value => _value;
}Can you add that as well?
Co-authored-by: Bill Wagner <wiwagn@microsoft.com>
|
@BillWagner while changing this i noticed the current example has a bug. |
@BarionLP This is interesting. I want to loop in @333fred and @AlekseyTs on this part. I had thought making the record type Everything looks good, but I'd like to get their thoughts before we finalize and merge this. |
Summary
clarify that all union members must be part of the interface
so far the paragraph mostly talks about factory methods.
Internal previews